package logic

import (
	"context"
	"house/models/cache"
	"house/pkg"
	"time"

	"house/userrpc/internal/svc"
	"house/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SetcacheLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSetcacheLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetcacheLogic {
	return &SetcacheLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SetcacheLogic) Setcache(in *userrpc.SetcacheRequest) (*userrpc.SetcacheResponse, error) {
	// todo: add your logic here and delete this line
	ip := pkg.GetOutboundIP()
	cache.Rdb.Set(l.ctx, "token"+ip, in.Token, time.Hour*1)
	return &userrpc.SetcacheResponse{}, nil
}
